def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n * 0.5) + 1):
        if n % i == 0:
            return False
    return True


def find_closest_prime(n):
    increment = 1
    while True:
        if is_prime(n + increment):
            return n + increment
        if is_prime(n - increment):
            return n - increment
        increment += 1


words_to_digits = {
    "zero": "0", "one": "1", "two": "2", "three": "3", "four": "4",
    "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"
}

input_words = input().split()

if len(input_words) != 3:
    print("Wrong input")
else:
    try:
        number_str = "".join([words_to_digits[word] for word in input_words])
        number = int(number_str)
        print(find_closest_prime(number))
    except KeyError:
        print("Wrong input")
